package com.lanchetech.admin.controller;

import com.lanchetech.admin.aop.OperatorLog;
import com.lanchetech.admin.service.FarmService;
import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.*;
import com.lanchetech.entity.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Api(value = "农场信息接口", tags = "农场信息接口")
@RequestMapping("/api/farm")
@RestController
public class FarmController {

    @Autowired
    FarmService farmService;

    @ApiOperation(value = "获取公告信息分页")
    @PreAuthorize("hasAuthority('farm.mail-box')")
    @PostMapping("/getMailBoxPage")
    public ResultData<BasePageResp<Mailbox>> getMailBoxPage(@RequestBody PageReq req) {
        return farmService.getMailBoxPage(req);
    }

    @OperatorLog("编辑公告信息")
    @ApiOperation(value = "编辑公告信息")
    @PreAuthorize("hasAuthority('farm.mail-box.edit.auth')")
    @PostMapping("/editMailBox")
    public BaseResp editMailBox(@RequestBody Mailbox mailbox) {
        return farmService.editMailBox(mailbox);
    }

    @ApiOperation(value = "获取公告信息详情")
    @PreAuthorize("hasAuthority('farm.mail-box-edit')")
    @GetMapping("/getMailBoxDetail")
    public ResultData<Mailbox> getMailBoxDetail(@RequestParam("id") Long id) {
        return farmService.getMailBoxDetail(id);
    }

    @OperatorLog("删除公告信息")
    @ApiOperation(value = "删除公告信息")
    @PreAuthorize("hasAuthority('farm.mail-box.edit.auth')")
    @GetMapping("/deleteMailBox")
    public BaseResp deleteMailBox(@RequestParam("id") Long id) {
        return farmService.deleteMailBox(id);
    }

    @ApiOperation(value = "获取草料流水分页")
    @PreAuthorize("hasAuthority('farm.grass-flow')")
    @PostMapping("/getGrassFlowPage")
    public ResultData<BasePageResp<GrassFlowVO>> getGrassFlowPage(@RequestBody PageReq req) {
        return farmService.getGrassFlowPage(req);
    }

    @ApiOperation(value = "获取水能量流水分页")
    @PreAuthorize("hasAuthority('farm.water-flow')")
    @PostMapping("/getWaterFlowPage")
    public ResultData<BasePageResp<WaterFlowVO>> getWaterFlowPage(@RequestBody PageReq req) {
        return farmService.getWaterFlowPage(req);
    }

    @ApiOperation(value = "获取农场用户分页")
    @PreAuthorize("hasAuthority('farm.farm-user')")
    @PostMapping("/getFarmUserPage")
    public ResultData<BasePageResp<FarmUserListVO>> getFarmUserPage(@RequestBody PageReq req) {
        return farmService.getFarmUserPage(req);
    }

    @ApiOperation(value = "获取农场产品分页")
    @PreAuthorize("hasAuthority('farm.farm-product')")
    @PostMapping("/getFarmProductPage")
    public ResultData<BasePageResp<FarmProduct>> getFarmProductPage(@RequestBody PageReq req) {
        return farmService.getFarmProductPage(req);
    }

    @OperatorLog("编辑农场产品")
    @ApiOperation(value = "编辑农场产品")
    @PreAuthorize("hasAuthority('farm.farm-product.edit.auth')")
    @PostMapping("/editFarmProduct")
    public BaseResp editFarmProduct(@RequestBody FarmProduct farmProduct) {
        return farmService.editFarmProduct(farmProduct);
    }

    @ApiOperation(value = "获取农场产品详情")
    @GetMapping("/getFarmProductDetail")
    public ResultData<FarmProduct> getFarmProductDetail(@RequestParam("id") Long id) {
        return farmService.getFarmProductDetail(id);
    }

    @OperatorLog("删除农场产品")
    @ApiOperation(value = "删除农场产品")
    @PreAuthorize("hasAuthority('farm.farm-product.delete.auth')")
    @GetMapping("/deleteFarmProduct")
    public BaseResp deleteFarmProduct(@RequestParam("id") Long id) {
        return farmService.deleteFarmProduct(id);
    }

    @ApiOperation(value = "获取农场订单")
    @PreAuthorize("hasAuthority('farm.farm-order')")
    @PostMapping("/getFarmProductOrderPage")
    public ResultData<BasePageResp<FarmOrderVO>> getFarmProductOrderPage(@RequestBody PageReq req) {
        return farmService.getFarmProductOrderPage(req);
    }

    @OperatorLog("农场订单发货")
    @ApiOperation(value = "农场订单发货")
    @PreAuthorize("hasAuthority('farm.farm-order.edit.auth')")
    @PostMapping("/editFarmOrderLogistics")
    public BaseResp editFarmOrderLogistics(@RequestBody FarmOrder req) {
        return farmService.editFarmOrderLogistics(req);
    }

    @ApiOperation(value = "获取农场订单详情")
    @PreAuthorize("hasAuthority('farm.farm-order-detail')")
    @GetMapping("/getFarmProductOrderDetail")
    public ResultData<FarmOrderVO> getFarmProductOrderDetail(@RequestParam("id") Long id) {
        return farmService.getFarmProductOrderDetail(id);
    }

    @ApiOperation(value = "获取奶牛分页")
    @PreAuthorize("hasAuthority('farm.cow-list')")
    @PostMapping("/getUserCowPage")
    public ResultData<BasePageResp<UserCowListVO>> getUserCowPage(@RequestBody PageReq req) {
        return farmService.getUserCowPage(req);
    }

    @ApiOperation(value = "获取用户果树分页")
    @PreAuthorize("hasAuthority('farm.tree-list')")
    @PostMapping("/getUserTreePage")
    public ResultData<BasePageResp<UserTreeListVO>> getUserTreePage(@RequestBody PageReq req) {
        return farmService.getUserTreePage(req);
    }

    @OperatorLog("编辑树苗设置")
    @ApiOperation(value = "编辑树苗设置")
    @PreAuthorize("hasAuthority('farm.sapling.edit.auth')")
    @PostMapping("/editSaplingConfig")
    public BaseResp editSaplingConfig(@RequestBody Sapling sapling) {
        return farmService.editSaplingConfig(sapling);
    }

    @ApiOperation(value = "获取树苗分页")
    @PreAuthorize("hasAuthority('farm.sapling')")
    @PostMapping("/getSaplingPage")
    public ResultData<BasePageResp<Sapling>> getSaplingPage(@RequestBody PageReq req) {
        return farmService.getSaplingPage(req);
    }

    @ApiOperation(value = "获取树苗详情")
    @PreAuthorize("hasAuthority('farm.sapling.edit.auth')")
    @GetMapping("/getSaplingDetail")
    public ResultData<Sapling> getSaplingDetail(@RequestParam("id") Long id) {
        return farmService.getSaplingDetail(id);
    }

    @ApiOperation(value = "获取农场任务分页")
    @PreAuthorize("hasAuthority('farm.task-list')")
    @PostMapping("/getFarmTaskPage")
    public ResultData<BasePageResp<FarmTask>> getFarmTaskPage(@RequestBody PageReq req) {
        return farmService.getFarmTaskPage(req);
    }

    @OperatorLog("编辑农场任务")
    @ApiOperation(value = "编辑农场任务")
    @PreAuthorize("hasAuthority('farm.task-list.edit.auth')")
    @PostMapping("/editFarmTask")
    public BaseResp editFarmTask(@RequestBody FarmTask farmTask) {
        return farmService.editFarmTask(farmTask);
    }

    @ApiOperation(value = "获取农场任务详情")
    @PreAuthorize("hasAuthority('farm.task-list.edit.auth')")
    @GetMapping("/getFarmTaskDetail")
    public ResultData<FarmTask> getFarmTaskDetail(@RequestParam("id") Long id) {
        return farmService.getFarmTaskDetail(id);
    }

    @OperatorLog("删除农场任务")
    @ApiOperation(value = "删除农场任务")
    @PreAuthorize("hasAuthority('farm.task-list.edit.auth')")
    @GetMapping("/deleteFarmTask")
    public BaseResp deleteFarmTask(@RequestParam("id") Long id) {
        return farmService.deleteFarmTask(id);
    }

}
